package com.walker.simple;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.walker.BaseConfig;

/**
 * @Description:
 * @ProjectName: walker-step
 * @Package: com.walker.simple
 * @ClassName: SimpleSender
 * @Author: yangyl
 * @CreateDate: 2020/6/20 17:14
 */
public class SimpleSender {

    private final static String QUEUE_NAME = "hello";

    public static ConnectionFactory getConnectionFactory() {
            ConnectionFactory connectionFactory = new ConnectionFactory();
            connectionFactory.setHost(BaseConfig.HOST);
            connectionFactory.setVirtualHost(BaseConfig.VHOST);
            connectionFactory.setPort(5672);
            connectionFactory.setUsername(BaseConfig.USERNAME);
            connectionFactory.setPassword(BaseConfig.PASSWORD);
            return connectionFactory;
    }

    public static void main(String[] args) throws Exception {
        ConnectionFactory connectionFactory = getConnectionFactory();
        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare(QUEUE_NAME, true, false, false, null);

        String body = "Hello World-1234";
        String exchange = "hello-exchange-first";
        String routKey = "hello-routKey-first";
        for (int i = 0; i < 10; i++) {
            byte[] data = (body + i).getBytes();
            channel.basicPublish("", QUEUE_NAME, null, data);

        }
        System.out.println("send data success.");
        channel.close();
        connection.close();
    }
}
